// 二级标题
import "./index.scss";
import { useRef } from "react";
const FirstTitle = (props) => {
  const targetRef = useRef(null);
  const toTop = () => {
    if (targetRef.current) {
      const element: any = targetRef.current;
      const offsetTop = element.offsetTop;

      const parent = document.getElementById("content-parent") as HTMLElement;
      parent.scrollTo({
        top: offsetTop - 10,
        behavior: "smooth",
      });
    }
  };
  return (
    <h1 onClick={() => toTop()} ref={targetRef} className="first-title">
      H1 {props.title}
    </h1>
  );
};

export default FirstTitle;
